<?
ob_start(); 
include("common/header.html");
include('common/autoload.php');
$out_html=ob_get_contents();
ob_end_clean();
include_once("class/ProOrder.php");

// 异步获取对应的景点门票
if($_SERVER['HTTP_REQUEST_TYPE']=='getTicket'){
	$sql='SELECT id,title FROM uu_jq_ticket WHERE landid='.($_REQUEST['landid']+0);//
	$GLOBALS['le']->query($sql);
	$tickes = array();
	while($row=$GLOBALS['le']->fetch_assoc()){
		$tickes[]=$row;
	}
	if(count($tickes)){
		echo json_encode(array('s'=>'success','content'=>$tickes));
	}else{
		echo json_encode(array('s'=>'fail'));
	}
	exit;
}

$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$memberID=$_SESSION['sid'];

$aid = isset($_REQUEST['aid']) ? abs($_REQUEST['aid']) : 0;

//获取分销商 供查找子票所属的套票分销给了哪个分销商使用
if($_SESSION['dtype']==0 || $_SESSION['dtype']==1 || $_SESSION['dtype']==6 || $_SESSION['dtype']==7) {
	include 'getDistors.php';
	$memberID = ($_SESSION['dtype']==6 || $_SESSION['dtype']==7) ? $_SESSION['sid']:$_SESSION['memberID'];
    if($_SESSION['dtype']==7){
		$FenstorsNames = getAll($GLOBALS['le'],$memberID);
	}else{
		$FenstorsNames = getRetail($GLOBALS['le'],$memberID);
	}
}


// 分销商获取供应商
if($_SESSION['dtype']==0 || $_SESSION['dtype']==1) {
    $DistorsNames = getDistors($GLOBALS['le']);
	$dTypeName = '供应商';
}

$object=buyProOrderObject($memberID,$s,$_SESSION['sdtype']);
//交易时间类型
$timeType = isset($_REQUEST['xtimes'])? abs($_REQUEST['xtimes']) : 1;
$btime=$_REQUEST['begintime']?trim($_REQUEST['begintime']):date("Y-m-01");
$etime=$_REQUEST['endtime']?trim($_REQUEST['endtime']):date("Y-m-d");
$btime = strpos($btime,":")!==false?$btime : $btime." 00:00:00";
$etime = strpos($etime,":")!==false?$etime : $etime." 23:59:59";
$by=$_REQUEST['by']?$_REQUEST['by']:"lid";
$option=array();
// 景点查询
if(isset($_REQUEST['landid']))	$option['lid']=$_REQUEST['landid'];

// 景点门票查询
if(isset($_REQUEST['ticket'])){
	$t = explode("_",$_REQUEST['ticket']);
	$option['tid']=$t[0];
}

if(count($_REQUEST['status'])>0){
	$option['status']=implode("|",$_REQUEST['status']);
}
$fenid = isset($_REQUEST['fenid']) ? abs($_REQUEST['fenid']) : '';

if(!$_REQUEST['begintime'] && !$_REQUEST['endtime'])
    goto one;
/*
if($_GET['xtimes']==3){
    $_GET['fid'] = $_SESSION['sid'];
    include_once 'module/zax/order_report/cetX.php';
    goto one;
}
*/
$r=$object->_orderSum($btime,$etime,$by,$option,$timeType,0,$aid,$fenid);



//TODO::加载会员数据 ---By Cgp
$memberNames = require dirname(__FILE__) . '/module/link_product/Member.cache.php';
if($_REQUEST['by']=='mid' && $_GET['order_type']!=2){
    foreach($r as $k => $v){
        if($k==0) {
            $r[$k]['title'] = '<span style="color:red;">'.$memberNames[$_SESSION['memberID']].'(自供自销)</span>';
        }
        else if($_SESSION['memberID']==1 && $_SESSION['dtype']==9){
            $r[$k]['title']=$aDistorsNames[$k];
        }else{
            $r[$k]['title']=$memberNames[$k];
        }
    }
}else if($_REQUEST['by']=='mid' && $_GET['order_type']==2){
    foreach($r as $k => $v){
        //取消订单里面 $k的组成是mid+时间  先取到时间里的 横杠的位置 然后往前再取4位
        $time_pos = strpos($k,'-');
        $mid = substr($k,0,$time_pos-4);
        $r[$k]['title']=$memberNames[$mid];
    }
}



/*导出EXCEL处理程序--begin-*/
//include("ExcelHandle.php");
/*导出EXCEL处理程序--end*/



$products=$object->getOrderProducts(); // 订单中的产品列表
if($_REQUEST['proList']){ //以有产品列表比查询出来的少更新
	$tmp = unserialize($_REQUEST['proList']);
	if(count($products)<=count($tmp)){
		$products = $tmp;
		$proList = serialize($tmp);
	}else{
		$proList = serialize($products);
	}
}else{
	$proList = serialize($products);
}

one:
$titleT=array("lid"=>"景区名称","tid"=>"票类名称","mid"=>"分销商名称");
$totals=array();
$hTitle="购买报表";
echo $out_html;

//取景点
$land = array();
include("/var/www/html/new/d/class/Member.php");
$m = new Member($s,$memberID);
$sale = $m->salePros();
foreach($sale as $v){
    if(!$land[$v['lid']])
    $land[$v['lid']]= $v['title'];
}

$from='buy';
include("tpl/orderReport.tpl");

include("common/footer.html");
?>
<style type="text/css">
	.maskLayer{ display:none; position:fixed; top:0; right:0; left:0; bottom:0; background:rgba(255,255,255,.5)}
	.lt-ie10.maskLayer{ background:#fff; filter:Alpha(opacity=50)}
	.orderListContainer{ display:none; width:300px; position:fixed; top:100px; left:50%; margin:0 0 0 -150px; background:#fff;
		-webkit-box-shadow:1px 1px 2px rgba(0,0,0,.3)
	}
	.orderListContainer .tit{ padding:0px 15px; height:40px; line-height:40px; border-bottom:1px solid #e3e3e3; background:#f9f9f9}
	.orderListContainer.lt-ie10{ border:1px solid #d5d5d5}
	.orderListContainer .listUl{ padding:5px 15px 15px; height:450px; overflow:auto;}
	.orderListContainer .listUl li{ float:left; width:47%; height:35px; line-height:35px; padding-left:2%;}
	.orderListContainer .closePopBtn{ display:block; position:absolute; width:40px; height:40px; top:0; right:0; background:url("http://www.12301.cc/images/other/dialog_close_btn_2.png") no-repeat 0 0}
	.orderListContainer .closePopBtn:hover{ background-position:top right}
</style>
<!--[if lt IE 7]><div id="maskLayer" class="lt-ie10 lt-ie9 lt-ie8 lt-ie7 ie6 maskLayer"> <![endif]-->
<!--[if IE 7]><div id="maskLayer" class="lt-ie10 lt-ie9 lt-ie8 ie7 maskLayer"> <![endif]-->
<!--[if IE 8]><div id="maskLayer" class="lt-ie10 lt-ie9 ie8 maskLayer"> <![endif]-->
<!--[if IE 9]><div id="maskLayer" class="lt-ie10 ie9 maskLayer"><![endif]-->
<!--[if gt IE 9]><!--><div id="maskLayer" class="maskLayer"> <!--<![endif]-->
</div>
<!--[if lt IE 7]><div id="orderListContainer" class="lt-ie10 lt-ie9 lt-ie8 lt-ie7 ie6 orderListContainer"> <![endif]-->
<!--[if IE 7]><div id="orderListContainer" class="lt-ie10 lt-ie9 lt-ie8 ie7 orderListContainer"> <![endif]-->
<!--[if IE 8]><div id="orderListContainer" class="lt-ie10 lt-ie9 ie8 orderListContainer"> <![endif]-->
<!--[if IE 9]><div id="orderListContainer" class="lt-ie10 ie9 orderListContainer"><![endif]-->
<!--[if gt IE 9]><!--><div id="orderListContainer" class="orderListContainer"> <!--<![endif]-->
	<a id="closePopBtn" class="closePopBtn" href="###"></a>
	<p class="tit">景区：<span class="jqname" style="margin:0 5px; font-weight:bold"></span>订单号列表</p>
	<ul class="listUl"></ul>
</div>
<script type="text/javascript">
var Pop = (function(){

	function init(){
		$("#offmain").on("click",".queryonumBtn",function(e){
			var target = $(e.currentTarget);
			var orders = target.prev().val();
			var tit = target.parents("tr").children(".tL").text();
			console.log(tit)
			$("#orderListContainer").find(".tit .jqname").text(tit);
			orders && showOrderNum(orders);
		})
		$("#closePopBtn").on("click",function(e){
			closeDialog()
		})
	}
	function showOrderNum(orders){
		orders = orders.split(",");
		var li = "";
		for(var i= 0,len=orders.length; i<len; i++){
			li += '<li class="oitem">'+orders[i]+'</li>';
		}
		$("#orderListContainer .listUl").html(li);
		openDialog();
	}
	function openDialog(){
		$("#orderListContainer").show();
		$("#maskLayer").show();
	}
	function closeDialog(){
		$("#orderListContainer").hide();
		$("#maskLayer").hide();
	}

	return {init:init}

})();

$(function(){
	Pop.init()
})
</script>
